package com.webshop.sbm.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Created by lvyuru on 2014/6/4.
 */
@Controller
@RequestMapping("/redirectController")
public class RedirectController {
    private static final String prefixRedirect="/redirect/";
    @RequestMapping(prefixRedirect+"**/{fileName}")
    public String redirect(@PathVariable String fileName,HttpServletRequest request,Model model){
        String redirectPath=request.getServletPath();
        Map<String,String[]> paramMap=request.getParameterMap();
        for(Map.Entry<String,String[]> entry:paramMap.entrySet()){
            model.addAttribute(entry.getKey(),entry.getValue()[0]);
        }
        return redirectPath.substring(redirectPath.indexOf(prefixRedirect)+prefixRedirect.length(),redirectPath.lastIndexOf(fileName)+fileName.length());
    }
}
